package cn.xo68.boot.groovyscript.engine;

import cn.xo68.boot.groovyscript.common.ScriptBuilder;
import cn.xo68.core.date.DateTime;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import groovy.lang.Script;


class GroovyScriptTest extends Script{
 
    public static String getString(String string){
        return string;
    }
 
    public static int getInt(){
        return 1;
    }
 
    @Override
    public Object run() {
        return null;
    }
 
    public static void main(String[] args){

        GroovyScriptExcutor groovyScriptExcutor=new GroovyScriptExcutor();

        ScriptBuilder scriptBuilder= ScriptBuilder.create()
                .appendLine("import cn.xo68.core.date.DateTime;")
                .appendLine("name = name + \"-leader\"")
                .appendLine("bookName = '红楼梦'")
                .appendLine("today = DateTime.Now().getDate()")
                .appendLine("currentTime = currentTime.addDay(10)")
                .appendLine("println name")
                .appendLine("return 37");

        Binding binding=new Binding();
        binding.setVariable("name","wuxie");
        DateTime dt=DateTime.Now().addDay(-1);
        System.out.println(dt.toString());
        binding.setVariable("currentTime", dt);
        Object returnValue = groovyScriptExcutor.excute(scriptBuilder, binding);
        System.out.println(returnValue);

        //System.out.println(binding1.getProperty("bookName"));
        System.out.println(binding.getVariables());
        System.out.println(dt.toString());
    }
 
}